{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#source: https://github.com/llSourcell/linear_regression_live/blob/master/demo.py\n",
    "# y = mx + b\n",
    "# m is slope, b is y-intercept\n",
    "def compute_error_for_line_given_points(b, m, coordinates):\n",
    "    totalError = 0\n",
    "    for i in range(0, len(coordinates)):\n",
    "        x = coordinates[i][0]\n",
    "        y = coordinates[i][1]\n",
    "        totalError += (y - (m * x + b)) ** 2\n",
    "    return totalError / float(len(coordinates))\n",
    "# example \n",
    "compute_error_for_line_given_points(1, 2, [[3,6],[6,9],[12,18]])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
